<?php


namespace app\common\model;
use app\common\model\Base;

class Goods extends Base
{

    // 定义获取器
    public function getStateAttr($value)
    {
        $status = [1=>"启用",0=>"禁用"];
        return $status[$value];
    }

    // 一对一关联(当前商品属于某种分类)
    public function className()
    {
        return $this->belongsTo('GoodsClass','class_id','id');
    }

    public function brandName()
    {
        return $this->belongsTo('Brand','brand_id','id');
    }

    /*
     * @Notes: 获取商品的详情
     * @Return $data
     * */
    public static function goodsTails($is_hot)
    {
        $res = Goods::with(['class_name'=> function($query) {
            $query->field('id,class_name');
        },'brand_name' => function($query) use ($is_hot) {
            $query->where(['is_hot'=>$is_hot])->field('id,brand_name');
        } ])->where(['id'=>1])->visible(['id','goods_name','goods_code','goods_title','goods_img'])->find();
        return $res;
    }


}